<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <c:set var="ctx" value="${pageContext.request.contextPath}"/>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>活体白名单</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>
<body>
<form id="add_form">
    <div class="fieldset1 tabel_col tabel_col_s clearFix noBorder">
        <div class="fieldBox col_50">
            <div class="label">客户姓名</div>
            <div class="field">
                <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="" validate="{required:true}">
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_50">
            <div class="label">手机号</div>
            <div class="field">
                <input name="mp" id="mp" type="text" class="ui-textbox" value="" validate="{required:true}">
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_50">
            <div class="label">业务类型代码</div>
            <div class="field">
                <select name="busTypCd" id="busTypCd" data-value=" ">
                    <option value=" " seleted>请选择</option>
                    <c:forEach items="${busTypCdList }" var="kv">
                        <option value="${kv.key }">${kv.value }</option>
                    </c:forEach>
                </select>
            </div>
        </div>

        <div class="fieldBox col_50">
            <div class="label">渠道</div>
            <div class="field">
                <input name="liveChannelCd" id="liveChannelCd" type="text" class="ui-textbox" value="">
            </div>
        </div>


        <div class="fieldBox col_50">
            <div class="label">BID</div>
            <div class="field">
                <input name="bid" id="bid" type="text" class="ui-textbox" value="">
            </div>
        </div>

        <div class="fieldBox col_50">
            <div class="label">PID</div>
            <div class="field">
                <input name="pid" id="pid" type="text" class="ui-textbox" value="">
            </div>
        </div>

        <div class="fieldBox col_50">
            <div class="label">证件类型</div>
            <div class="field">
                <select name="certTypCd" id="certTypCd" data-value=" ">
                    <c:forEach items="${certTypCdList }" var="kv">
                        <option value="${kv.key }">${kv.value }</option>
                    </c:forEach>
                </select>
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_50">
            <div class="label">证件号码</div>
            <div class="field">
                <input name="certNo" id="certNo" type="text" class="ui-textbox" value="" validate="{required:true}">
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_50">
            <div class="label">开始时间</div>
            <div class="field">
                <input name="startTm" id="startTm" type="text" class="ui-datepicker" ligerui="{showTime:true}"
                       value="" validate="{required:true}">
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_50">
            <div class="label">结束时间</div>
            <div class="field">
                <input name="endTm" id="endTm" type="text" class="ui-datepicker" ligerui="{showTime:true}"
                       value="" validate="{required:true}">
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_50">
            <div class="label">可用次数</div>
            <div class="field">
                <input name="times" id="times" type="text" class="ui-textbox" ligerui="{type:'int'}"
                       validate="{required:true}" value="">
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_50">
            <div class="label">备注</div>
            <div class="field">
                <input name="remark" id="remark" type="text" class="ui-textbox" value="">
            </div>
        </div>

        <div class="fieldset1 tabel_col tabel_col_s clearFix">
            <div class="caption">
                <span class="title">附件信息</span>
            </div>
            <div class="fieldBox col_100" id="fileModify">
                <div class="label">资料</div>
                <div class="field">
                    <jsp:include page="../../system/sysUlFilesRec/sysUlFileRecList.jsp" flush="true">
                        <jsp:param name="pkId" value="${id }"/>
                        <jsp:param name="tabNm" value=""/>
                    </jsp:include>
                </div>
            </div>
            <div class="fieldBox col_100">
                <div class="label">资料上传</div>
                <div class="field">
                    <jsp:include page="../../system/sysUlFilesRec/sysSysUlFilesRecUpload2.jsp" flush="true">
                        <jsp:param name="filePath" value="cmmwhite"/>
                    </jsp:include>
                </div>
            </div>
            <!-- hide data -->
            <div class="fieldBox col_100" style="display:none;">
                <div class="field">
                    <input name="dataId" id="dataId" type="text" class="ui-textbox" value="${id}">
                </div>
            </div>
        </div>
    </div>
</form>
<script>
    $(function () {
        $("#add_form").ligerForm({
            validate: true
        });
        initData();
    });

    //定义父级调用事件
    frameElement.dialog.onOk = function () {
        save();
    }

    frameElement.dialog.onCancel = function () {
        frameElement.dialog.close();
    }

    //保存
    function save() {
        var ligerForm = liger.get("add_form");
        if (!ligerForm.valid()) {
            UIUtils.alertWarning("有验证信息未通过!");
            return; //验证不通过，不执行以下代码
        }
        var data = ligerForm.getData();
        data.startTm = $("#startTm").val();
        data.endTm = $("#endTm").val();

        var docArray = JSON.stringify(getUploadResultParams());
        //赋值附件
        data["docArray"] = docArray;
        var dataId = $("#dataId").val();
        var url = '<%=path%>/custpay/cmmwhitelist/add.do';
        if (StringUtils.isNotEmpty(dataId)) {
            url = '<%=path%>/custpay/cmmwhitelist/modify.do';
            data["id"] = dataId;
        }else{
            data.isValid = "1";//默认有效
            data.listTypCd = "1";//默认白名单
        }
        AjaxUtils.ajaxPost(url, data, addCallback);
    }


    //新增回调
    function addCallback(msg) {
        if (msg.success == 1) {
            parent.grid.reload();
            UIUtils.alertSuccess("操作成功!");
            frameElement.dialog.close();
        } else {
            UIUtils.alertError(msg.info);
        }
    }

    //修改初始化数据
    function initData() {
        var dataId = $("#dataId").val();
        if (StringUtils.isEmpty(dataId)) {
            //初始化开始时间为当前时间
            var form = liger.get("add_form");
            var date = new Date();
            form.setData({
                startTm: date
            });
            return;
        }
        var _url = '<%=path%>/custpay/cmmwhitelist/getById.do';
        AjaxUtils.ajaxGet(_url, {id: dataId}, initCallback);
    }

    //初始化回调
    function initCallback(msg) {
        if (msg.success == 1) {
            setData(msg.data);//设置数据
        } else {
            UIUtils.alertError(msg.info);
        }
    }

    //修改时候设置页面数据
    function setData(data) {
        var form = new liger.get("add_form");
        form.setData({
            cstNm: data.cstNm,
            certTypCd: data.certTypCd,
            certNo: data.certNo,
            startTm: data.startTm,
            endTm: data.endTm,
            remark: data.remark,
            mp: data.mp,
            bid: data.bId,
            pid: data.pId,
            busTypCd: data.busTypeCd,
            liveChannelCd: data.liveChannelCd,
            times: data.availableTimes
        });
    };
</script>

</body>
</html>